package com.java.frontweb.controller;


import com.java.frontweb.pojo.Item;
import com.java.frontweb.service.ItemService;
import com.java.manage.pojo.TbItemDesc;
import com.java.manage.service.TbItemDescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author TriggerWu
 * @since 2018-09-13
 */
@Controller
@RequestMapping("rest/item")
public class ItemController {
    @Autowired
    private ItemService itemService;
    @Autowired
    private  TbItemDescService itemDescService;

    @RequestMapping(value = "{itemId}", method = RequestMethod.GET)
    public ModelAndView itemDetail(@PathVariable("itemId") Long itemId) {
        ModelAndView mv = new ModelAndView("item");
        // 设置模型数据

        Item item = itemService.queryById(itemId);
        mv.addObject("item", item);

        // 商品描述数据
        TbItemDesc itemDesc = itemService.queryDescByItemId(itemId);
        mv.addObject("itemDesc", itemDesc);

        // 商品规格参数数据
        String itemParam = this.itemService.queryItemParamItemByItemId(itemId);
        mv.addObject("itemParam", itemParam);
        return mv;
    }
}

